<{assign var="page_title" value="管理用户" }>
<{include file="FASHION/page_header.html"}>

<h3><{$page_title}></h3>

<table border="1" id="list">
<tr>
	<th>UID</th>
	<th>用户名</th>
	<th>昵称</th>
	<th>邮箱</th>
	<th>属组</th>
	<th>状态</th>
	<th>时间</th>
	<th>OP</th>
</tr>
<{foreach item=u from=$list}>
<tr user_id="<{$u.user_id}>">
	<td><{$u.user_id}></td>
	<td class="name"><{$u.name}></td>
	<td class="nickname"><{$u.nickname}></td>
	<td class="email"><{$u.email}></td>
	<td class="group_id" group_id="<{$u.group_id}>"><{$groups[$u.group_id].title}></td>
	<td class="is_disa"><div class="icon_s disa_<{$u.is_disa}>" is_disa="<{$u.is_disa}>" user_id="<{$u.user_id}>"></div></td>
	<td><{$u.atime|date_format:"%D"}></td>
	<td>
		<a href="javascript:;" onclick="modify('<{$u.user_id}>')" class="icon_s modify" title="修改"></a>
		<a href="javascript:;" onclick="location.href='<{url a=user-role id=$u.user_id}>'" class="icon_s role" title="角色"></a>
		<!--<a href="javascript:;" onclick="del('<{$u.user_id}>')" class="icon_s remove" title="删除"></a>-->
	</td>
</tr>
<{/foreach}>
</table>

<br/>
<input type="button" value="增加用户" onclick="add()" />

<div id="dialog" title="新建用户" style="display:none;">
	<form action="<{url a='user-save'}>" method="post" id="form1">
	<table border="0" width="100%">
	<tr>
		<td width="23%" align="right">用户名</td>
		<td><input type="text" name="name" class="text ui-widget-content ui-corner-all" value="" /></td>
	</tr>
	<tr>
		<td align="right">密码</td>
		<td><input type="password" name="passwd" class="text ui-widget-content ui-corner-all" value="" /></td>
	</tr>
	<tr>
		<td align="right">昵称</td>
		<td><input type="text" name="nickname" class="text ui-widget-content ui-corner-all" value="" /></td>
	</tr>
	<tr>
		<td align="right">邮箱</td>
		<td><input type="text" name="email" class="text ui-widget-content ui-corner-all" value="" /></td>
	</tr>
	<tr>
		<td align="right">属组</td>
		<td><select name="group_id">
			<option value=""></option>
<{foreach item=g from=$groups}>
			<option value="<{$g.group_id}>"><{$g.title}></option>
<{/foreach}>
		</select></td>
	</tr>
	</table>
	<input type="hidden" name="user_id" id="user_id" value="" />
	</form>
</div>

<script>

$("#dialog").dialog({
	bgiframe:	1,
	resizable:	1,
	autoOpen:	0,
	height:		240,
	width:		350,
	modal:		1,
	buttons: {
		'取消': function() {
			$(this).dialog('close');
			$("#form1").get(0).reset();
		},
		'保存': function() {
			$("#form1").submit();
		}
	}
});


$("#form1").ajaxForm({
	'beforeSubmit' : function(){
	},
	'success' :	function(jsn){
		if(jsn.level=='notice') {	//成功
			if(jsn.html)
			{
				if(jsn.method=='insert') {
					$("#list").append(jsn.html);
				}
				else {
					$("#list tr[user_id="+jsn.user_id+"]").replaceWith(jsn.html);
				}
			}
			$("#dialog").dialog('close');
			$("#form1").get(0).reset();
		}
		alert(jsn.message);
	}
});

function add()
{
	$('#dialog').dialog('open');
	$("#form1").get(0).reset();
	$('#form1 input[name=name]').attr('disabled', false);
	$("#user_id").val('');
}

function modify(user_id)
{
	$('#dialog').dialog('open');

	$("#form1 input[name=user_id]").val(user_id);
	$("#form1 input[name=name]").val($("tr[user_id="+user_id+"] td.name").html());
	$("#form1 input[name=nickname]").val($("tr[user_id="+user_id+"] td.nickname").html());
	$("#form1 input[name=email]").val($("tr[user_id="+user_id+"] td.email").html());
	$("#form1 select[name=group_id]").val($("tr[user_id="+user_id+"] td.group_id").attr('group_id'));
	$("#form1 input[name=name]").attr('disabled', true);
}

/*
function del(user_id)
{
	if(confirm('确认删除?'))
	{
		$.get('<{url a=user-delete user_id=USER_ID}>'.replace('USER_ID',user_id), function(jsn){
			if(jsn.level=='notice') {
				$("#sortable li[user_id="+user_id+"]").remove();
			}
			alert(jsn.message);
		});
	}
}
*/

$("div[is_disa]").click(function(){
	$.get('<{url a=user-disa user_id=USER_ID disa=DISA}>'
		.replace('USER_ID', $(this).attr('user_id'))
		.replace('DISA', $(this).attr('is_disa')), function(jsn){
			$("div[is_disa][user_id="+jsn.user_id+"]")
				.attr('class', 'icon_s disa_'+jsn.disa)
				.attr('is_disa', jsn.disa);
		});
});
</script>

<{include file="FASHION/page_footer.html"}>